import java.io.*;
import java.util.*;

public class Main {
	BufferedReader bf;
	StringTokenizer st;
	StringBuilder sb;
	
	int n,
		start,
		end;
	boolean[][] adjacency_matrix;
	
	public Main() {
		bf = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.beginProcess();
	}

	public void beginProcess() {
		try {
			int i,
				pos,
				idx;
			String input;
			List<Integer> visitedNode;
			
			while((input = bf.readLine()) != null) {
				st = new StringTokenizer(input);
				n = Integer.parseInt(st.nextToken());
				
				adjacency_matrix = new boolean[n][n];
				adjacency_matrix_init();
				for(i = 0; i < n; i++) {
					st = new StringTokenizer(bf.readLine());
					while(st.hasMoreElements()) {
						pos = Integer.parseInt(st.nextToken());
						if(pos == 0)
							break;
						adjacency_matrix[i][pos - 1] = true;
					}
				}
				st = new StringTokenizer(bf.readLine());
				start = Integer.parseInt(st.nextToken()) - 1;
				end = Integer.parseInt(st.nextToken()) - 1;

				idx = 0;
				visitedNode = new ArrayList<Integer>();
				visitedNode.add(idx, start);
				traversal(visitedNode);
			}

			System.out.print(sb);
		}
		catch(Exception ex) {
			System.err.println(ex.toString());
		}
	}
	
	private void traversal(List<Integer> visitedNode) {
		int i,
			j,
			idx = visitedNode.size() - 1;
		boolean yetVisited;
		List<Integer> copyVisitedNode;
		
		if(visitedNode.size() == n && visitedNode.get(visitedNode.size() - 1) == end) {
			String tmpStr = "";
			for(int node : visitedNode)
				tmpStr += (node + 1) + " ";
			tmpStr = tmpStr.substring(0, tmpStr.length() - 1);
			tmpStr += "\n";
			sb.append(tmpStr);
			return;
		}
		
		for(i = 0; i < n; i++) {
			yetVisited = true;
			if(adjacency_matrix[visitedNode.get(idx)][i]) {
				j = visitedNode.size() - 1;
				while(j >= 0) {
					if(i == visitedNode.get(j))
						yetVisited = false;
					j--;
				}
				if(yetVisited) {
					copyVisitedNode = new ArrayList<Integer>(visitedNode);
					copyVisitedNode.add(idx + 1, i);
					traversal(copyVisitedNode);
				}
			}
		}
	}

	private void adjacency_matrix_init() {
		int i,
			j;
		for(i = 0; i < adjacency_matrix.length; i++)
			for(j = 0; j < adjacency_matrix.length; j++)
				adjacency_matrix[i][j] = false;
	}
	
}